home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 8709 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.2 KB

  1. Path: mail2news.demon.co.uk!genesis.demon.co.uk
  2. From: Lawrence Kirby <fred@genesis.demon.co.uk>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Convert String to Int?
  5. Date: Tue, 05 Mar 96 17:29:52 GMT
  6. Organization: none
  7. Message-ID: <826046992snz@genesis.demon.co.uk>
  8. References: <4hf3sk$k57@hustle.rahul.net> <4hfs0l$k2i@newsbf02.news.aol.com>
  9. Reply-To: fred@genesis.demon.co.uk
  10. X-NNTP-Posting-Host: genesis.demon.co.uk
  11. X-Newsreader: Demon Internet Simple News v1.27
  12. X-Mail2News-Path: genesis.demon.co.uk
  13.  
  14. In article <4hfs0l$k2i@newsbf02.news.aol.com> razine@aol.com "Razine" writes:
  15.  
  16. >I would suggest using atoi.
  17. >
  18. >example
  19. >
  20. >#include <stdio.h>
  21. >#include <stdlib.h>
  22. >
  23. >int main()
  24. >{
  25. >
  26. >  char number[3]='999';
  27.  
  28. This should be:
  29.  
  30.    char number[4]="999";
  31.  
  32. or equivalently:
  33.  
  34.    char number[]="999";
  35.  
  36. atoi() requires that you pass it a string which means that the sequence
  37. of characters must be terminated by the null character.
  38.  
  39. >  int result;
  40. >
  41. >  result=atoi(number);
  42. >  printf("Result == %d\n",result);
  43. >  return 0;
  44. >  }
  45.  
  46. -- 
  47. -----------------------------------------
  48. Lawrence Kirby | fred@genesis.demon.co.uk
  49. Wilts, England | 70734.126@compuserve.com
  50. -----------------------------------------
  51.